<?php

class News extends Module{

	public function __construct(){
		$this->author = "Tomáš Voslař";
		$this->name = "Novinky";
		$this->presenter = "News";
		$this->version = "1.0";
		$this->params = "seo_title";
	}

	public function getSql(){
			
		dibi::query("CREATE TABLE IF NOT EXISTS `" . TABLE_PREFIX . "news` (
  				`id_news` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  				`date` datetime NOT NULL,
  				`title` varchar(255) NOT NULL,
  				`seo_title` varchar(255) NOT NULL,
  				`content` text NOT NULL,
  				`perex` text NOT NULL,
  				`id_file` int(10) NULL,
  				`id_menu` mediumint(8) NULL,
  				PRIMARY KEY (`id_news`)
				) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0;
				");
		
		dibi::query("CREATE TABLE IF NOT EXISTS `" . TABLE_PREFIX . "news_emails` (
  				`id_email` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  				`email` varchar(255) NOT NULL,
  				`active` tinyint(1) NOT NULL,
  				`hash`varchar(255) NOT NULL,
  				PRIMARY KEY (`id_email`)
				) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0;
				");
			
	}
	
	public function getSearch(){

		$search = array("presenter" => "News");
		
		return $search;
	}
	
	public function getSearchSql(){
		
		return $search = dibi::select("m.name_seo")->as("id")
					->select("CONCAT(n.title, ' :', n.content)")->as("searchText")
					->select("m.name")->as("searchName")
					->select("n.seo_title")
					->from(TABLE_MENU)->as("m")
					->leftJoin(TABLE_PREFIX."news")->as("n")
					->using("(id_menu)");
	}
	
	public function getSearchData(){
		
		$data = array("cond" => array("title", "content"), "presenter" => "News");
		
		return $data;
		
	}

}

?>